Permalink
Browse files

Initial import of ocs-1.0.2

  • Loading branch information...
Erick Tryzelaar
Erick Tryzelaar committed Apr 6, 2009
0 parents commit d8e98ee139362bf880a6f0cd14206a3951abc296
Showing with 5,909 additions and 0 deletions.
  1. +65 −0 CHANGES
  2. +25 −0 COPYING
  3. +136 −0 README
  4. +107 −0 src/.depend
  5. +57 −0 src/Makefile
  6. +21 −0 src/Makefile.common
  7. +153 −0 src/ocs_char.ml
  8. +9 −0 src/ocs_char.mli
  9. +473 −0 src/ocs_compile.ml
  10. +13 −0 src/ocs_compile.mli
  11. +44 −0 src/ocs_complex.ml
  12. +11 −0 src/ocs_complex.mli
  13. +114 −0 src/ocs_contin.ml
  14. +6 −0 src/ocs_contin.mli
  15. +143 −0 src/ocs_env.ml
  16. +30 −0 src/ocs_env.mli
  17. +11 −0 src/ocs_error.ml
  18. +339 −0 src/ocs_eval.ml
  19. +6 −0 src/ocs_eval.mli
  20. +224 −0 src/ocs_io.ml
  21. +11 −0 src/ocs_io.mli
  22. +279 −0 src/ocs_lex.ml
  23. +22 −0 src/ocs_lex.mli
  24. +302 −0 src/ocs_list.ml
  25. +6 −0 src/ocs_list.mli
  26. +438 −0 src/ocs_macro.ml
  27. +6 −0 src/ocs_macro.mli
  28. +28 −0 src/ocs_main.ml
  29. +77 −0 src/ocs_misc.ml
  30. +12 −0 src/ocs_misc.mli
  31. +633 −0 src/ocs_num.ml
  32. +13 −0 src/ocs_num.mli
  33. +201 −0 src/ocs_numaux.ml
  34. +29 −0 src/ocs_numaux.mli
  35. +403 −0 src/ocs_numstr.ml
  36. +11 −0 src/ocs_numstr.mli
  37. +223 −0 src/ocs_port.ml
  38. +33 −0 src/ocs_port.mli
  39. +269 −0 src/ocs_prim.ml
  40. +8 −0 src/ocs_prim.mli
  41. +75 −0 src/ocs_print.ml
  42. +9 −0 src/ocs_print.mli
  43. +87 −0 src/ocs_read.ml
  44. +10 −0 src/ocs_read.mli
  45. +153 −0 src/ocs_string.ml
  46. +6 −0 src/ocs_string.mli
  47. +59 −0 src/ocs_sym.ml
  48. +36 −0 src/ocs_sym.mli
  49. +75 −0 src/ocs_top.ml
  50. +10 −0 src/ocs_top.mli
  51. +200 −0 src/ocs_types.mli
  52. +65 −0 src/ocs_vartable.ml
  53. +13 −0 src/ocs_vartable.mli
  54. +79 −0 src/ocs_vector.ml
  55. +6 −0 src/ocs_vector.mli
  56. +35 −0 src/ocs_wrap.ml
65 CHANGES
@@ -0,0 +1,65 @@
+1.0.2
+
+ - Try to find a smaller invariant precision when converting from
+ floating point values to strings.
+
+ - Add missing function vector-fill!.
+
+ - Add an unspecified value that isn't printed by the repl.
+
+ - Add a value and functor that can be used to safely wrap arbitrary
+ OCaml values in Scheme values.
+
+ - Fix internal definitions inside (begin ...) forms.
+
+ - Consider literals in the literal list of syntax-rules locally
+ bound while parsing (but not while matching) patterns. R5RS is not
+ clear on this, but it is necessary to avoid breaking hygiene when
+ some expansions of an outer macro could change the interpretation of
+ pattern variables to literals within the patterns of inner macros.
+ This seems consistent with the behavior of other implementations.
+
+ - Fix namespace lookup for syntax-rules literals to allow changes
+ in global bindings.
+
+ - Fix namespace handling for nested macros.
+
+ - Fix copy-paste error in log.
+
+ - Fix the behavior of eval and arguments.
+
+ - Fix inexact->exact for negative numbers that don't fit into an
+ integer.
+
+ - The reader now also accepts square brackets [ and ] as list
+ delimiters.
+
+ - Fix remainder to handle differing signs correctly.
+
+1.0.1
+
+ - Fix sorting of byte code objects in Makefile.
+
+ - Add missing functions numerator and denominator.
+
+ - Keep rationals normalized.
+
+1.0 (changes from pre-releases)
+
+ - Rearrange build to generate bytecode and native libraries and a
+ native interpreter usable from the command line.
+
+ - Remove CVS Id's (the project is now being stored in a GNU Arch
+ repository) from all files.
+
+ - Fix Ocs_port.string_input_port to actually initialize the
+ port with the string length.
+
+ - Fix internal definitions of the form (define (fun args ...) ...).
+ Previously the first item of the body would be skipped.
+
+ - Fix the order of arguments to atan when called with two arguments.
+
+ - When invoking continuations with multiple arguments, the
+ arguments are now wrapped with Svalues as if (values ...) were used.
+
25 COPYING
@@ -0,0 +1,25 @@
+
+Copyright (c) 2003-2004 Ville-Pertti Keinonen
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.
+
136 README
@@ -0,0 +1,136 @@
+1. General
+
+Ocs is an implementation of Scheme, as defined by R5RS. It is
+written entirely in OCaml and can be trivially embedded in any
+OCaml program.
+
+Known deviations from R5RS:
+
+ - transcript-on and transcript-off are currently not implemented
+ - scheme-report-environment and null-environment ignore their
+ argument
+
+Anything else that does not work as specified in R5RS is a bug.
+
+
+2. Installation
+
+Requirements:
+
+ - GNU make or pmake (BSD make)
+ - OCaml 3.x (versions 3.06 and newer tested)
+
+Type make or gmake in the src directory. This should produce the
+following:
+
+ - A bytecode library (ocs.cma)
+ - A native library (ocs.cmxa, ocs.a)
+ - A stand-alone, native interpreter (ocscm)
+
+2.1 The 'ocscm' command
+
+If invoked without arguments, the interpreter will run in interactive
+mode.
+
+If invoked with arguments, the interpreter will read and evaluate
+the files listed as arguments and exit. The evaluation results are
+not printed.
+
+
+3. Implementation Details
+
+Implementing Scheme in OCaml is so straightforward that it hardly
+needs any documentation. The following mappings between languages
+are done:
+
+ - Scheme is dynamically typed. Scheme values are represented by
+the OCaml type Ocs_types.sval.
+
+ - In Scheme, top-level bindings are global and all variables are
+mutable. Variables references are bound through environments
+(Ocs_types.env) to global slots (Ocs_types.gvar) or frame indices
+(the actual frames are visible at evaluation-time through
+Ocs_types.thread).
+
+ - Scheme has capturable, first-class continuations. Most of the
+evaluator is written in continuation-passing style in order to allow
+this.
+
+Where discussing types, the rest of this section assumes that the
+types defined in the module Ocs_types are visible.
+
+3.1 Evaluation
+
+Scheme values (S-expressions) are of the type sval.
+
+Before evaluation Scheme values are compiled to internal representations
+of the type code. This is done by the function
+
+ Ocs_compile.compile : env -> sval -> code
+
+The env type is used during compilation for variable bindings. A
+new env is created for each new scope and frame. The base
+environment with the basic language bindings can be created using
+
+ Ocs_top.make_env : unit -> env
+
+Evaluation is done by
+
+ Ocs_eval.eval : thread -> (sval -> unit) -> code -> unit
+
+where the second argument is a continuation to pass the result to.
+
+The thread type is used during evaluation for storing the current
+frame and display for local variables, the input/output ports and
+the current dynamic extent. It does not represent a thread in the
+concurrent sense, but rather the evaluation state, and is copied and
+changed rather than modified in place. The initial thread to be
+passed to the evaluator can be created using
+Ocs_top.make_thread : unit -> thread.
+
+3.2 Continuations and I/O
+
+Any continuations captured are associated with the thread at the
+time of capture, so if a continuation is used to escape a
+with-input-from-file or with-output-to-file, the input/output port
+is restored to those of the time of capture.
+
+If a continuation is used to return to a with-input-from-file or
+with-output-to-file, the port is once again set to the one
+opened by the with-...-file call. However, if the thunk has
+already exited once, the port will be closed and no longer be
+valid for I/O calls.
+
+3.3 Numbers
+
+The full R5RS numeric tower is implemented, with the following
+internal representations:
+
+Exact numbers are
+ - 31- or 63-bit integers (OCaml int)
+ - Big_int objects from the Num library when unboxed integers are
+ too small
+ - Ratio objects from the Num library for rationals
+
+Inexact numbers are
+ - 64-bit IEEE floats for reals (OCaml float)
+ - Pairs of 64-bit IEEE floats for complex numbers (OCaml Complex.t)
+
+Since inexact numbers are represented internally as binary floating
+point, conversions to exact numbers are most precise for fractions of
+powers of two
+
+ (inexact->exact 2.125) ==> 17/8
+
+compared to
+
+ (inexact->exact 0.3) ==> 5404319552844595/18014398509481984
+
+And in fact many rationals will not satisfy
+
+ (= (inexact->exact (exact->inexact r)) r)
+
+However
+
+ (rationalize (inexact->exact 0.3) (expt 2 -54)) ==> 3/10
+
@@ -0,0 +1,107 @@
+ocs_char.cmo: ocs_types.cmi ocs_error.cmo ocs_env.cmi ocs_char.cmi
+ocs_char.cmx: ocs_types.cmi ocs_error.cmx ocs_env.cmx ocs_char.cmi
+ocs_compile.cmo: ocs_vartable.cmi ocs_types.cmi ocs_sym.cmi ocs_misc.cmi \
+ ocs_error.cmo ocs_env.cmi ocs_compile.cmi
+ocs_compile.cmx: ocs_vartable.cmx ocs_types.cmi ocs_sym.cmx ocs_misc.cmx \
+ ocs_error.cmx ocs_env.cmx ocs_compile.cmi
+ocs_complex.cmo: ocs_complex.cmi
+ocs_complex.cmx: ocs_complex.cmi
+ocs_contin.cmo: ocs_types.cmi ocs_misc.cmi ocs_eval.cmi ocs_error.cmo \
+ ocs_env.cmi ocs_contin.cmi
+ocs_contin.cmx: ocs_types.cmi ocs_misc.cmx ocs_eval.cmx ocs_error.cmx \
+ ocs_env.cmx ocs_contin.cmi
+ocs_env.cmo: ocs_vartable.cmi ocs_types.cmi ocs_sym.cmi ocs_error.cmo \
+ ocs_env.cmi
+ocs_env.cmx: ocs_vartable.cmx ocs_types.cmi ocs_sym.cmx ocs_error.cmx \
+ ocs_env.cmi
+ocs_eval.cmo: ocs_types.cmi ocs_sym.cmi ocs_misc.cmi ocs_error.cmo \
+ ocs_eval.cmi
+ocs_eval.cmx: ocs_types.cmi ocs_sym.cmx ocs_misc.cmx ocs_error.cmx \
+ ocs_eval.cmi
+ocs_io.cmo: ocs_types.cmi ocs_read.cmi ocs_print.cmi ocs_port.cmi \
+ ocs_eval.cmi ocs_error.cmo ocs_env.cmi ocs_io.cmi
+ocs_io.cmx: ocs_types.cmi ocs_read.cmx ocs_print.cmx ocs_port.cmx \
+ ocs_eval.cmx ocs_error.cmx ocs_env.cmx ocs_io.cmi
+ocs_lex.cmo: ocs_types.cmi ocs_port.cmi ocs_numstr.cmi ocs_error.cmo \
+ ocs_char.cmi ocs_lex.cmi
+ocs_lex.cmx: ocs_types.cmi ocs_port.cmx ocs_numstr.cmx ocs_error.cmx \
+ ocs_char.cmx ocs_lex.cmi
+ocs_list.cmo: ocs_types.cmi ocs_misc.cmi ocs_error.cmo ocs_env.cmi \
+ ocs_list.cmi
+ocs_list.cmx: ocs_types.cmi ocs_misc.cmx ocs_error.cmx ocs_env.cmx \
+ ocs_list.cmi
+ocs_macro.cmo: ocs_types.cmi ocs_sym.cmi ocs_misc.cmi ocs_error.cmo \
+ ocs_env.cmi ocs_compile.cmi ocs_macro.cmi
+ocs_macro.cmx: ocs_types.cmi ocs_sym.cmx ocs_misc.cmx ocs_error.cmx \
+ ocs_env.cmx ocs_compile.cmx ocs_macro.cmi
+ocs_main.cmo: ocs_types.cmi ocs_top.cmi ocs_prim.cmi ocs_error.cmo
+ocs_main.cmx: ocs_types.cmi ocs_top.cmx ocs_prim.cmx ocs_error.cmx
+ocs_misc.cmo: ocs_types.cmi ocs_error.cmo ocs_misc.cmi
+ocs_misc.cmx: ocs_types.cmi ocs_error.cmx ocs_misc.cmi
+ocs_num.cmo: ocs_types.cmi ocs_numaux.cmi ocs_error.cmo ocs_env.cmi \
+ ocs_complex.cmi ocs_num.cmi
+ocs_num.cmx: ocs_types.cmi ocs_numaux.cmx ocs_error.cmx ocs_env.cmx \
+ ocs_complex.cmx ocs_num.cmi
+ocs_numaux.cmo: ocs_types.cmi ocs_error.cmo ocs_numaux.cmi
+ocs_numaux.cmx: ocs_types.cmi ocs_error.cmx ocs_numaux.cmi
+ocs_numstr.cmo: ocs_types.cmi ocs_numaux.cmi ocs_num.cmi ocs_error.cmo \
+ ocs_env.cmi ocs_numstr.cmi
+ocs_numstr.cmx: ocs_types.cmi ocs_numaux.cmx ocs_num.cmx ocs_error.cmx \
+ ocs_env.cmx ocs_numstr.cmi
+ocs_port.cmo: ocs_error.cmo ocs_port.cmi
+ocs_port.cmx: ocs_error.cmx ocs_port.cmi
+ocs_prim.cmo: ocs_types.cmi ocs_sym.cmi ocs_read.cmi ocs_port.cmi \
+ ocs_misc.cmi ocs_macro.cmi ocs_lex.cmi ocs_io.cmi ocs_eval.cmi \
+ ocs_error.cmo ocs_env.cmi ocs_compile.cmi ocs_prim.cmi
+ocs_prim.cmx: ocs_types.cmi ocs_sym.cmx ocs_read.cmx ocs_port.cmx \
+ ocs_misc.cmx ocs_macro.cmx ocs_lex.cmx ocs_io.cmx ocs_eval.cmx \
+ ocs_error.cmx ocs_env.cmx ocs_compile.cmx ocs_prim.cmi
+ocs_print.cmo: ocs_types.cmi ocs_sym.cmi ocs_port.cmi ocs_numstr.cmi \
+ ocs_char.cmi ocs_print.cmi
+ocs_print.cmx: ocs_types.cmi ocs_sym.cmx ocs_port.cmx ocs_numstr.cmx \
+ ocs_char.cmx ocs_print.cmi
+ocs_read.cmo: ocs_types.cmi ocs_sym.cmi ocs_port.cmi ocs_misc.cmi ocs_lex.cmi \
+ ocs_error.cmo ocs_read.cmi
+ocs_read.cmx: ocs_types.cmi ocs_sym.cmx ocs_port.cmx ocs_misc.cmx ocs_lex.cmx \
+ ocs_error.cmx ocs_read.cmi
+ocs_string.cmo: ocs_types.cmi ocs_error.cmo ocs_env.cmi ocs_string.cmi
+ocs_string.cmx: ocs_types.cmi ocs_error.cmx ocs_env.cmx ocs_string.cmi
+ocs_sym.cmo: ocs_types.cmi ocs_error.cmo ocs_sym.cmi
+ocs_sym.cmx: ocs_types.cmi ocs_error.cmx ocs_sym.cmi
+ocs_top.cmo: ocs_vector.cmi ocs_types.cmi ocs_string.cmi ocs_read.cmi \
+ ocs_print.cmi ocs_prim.cmi ocs_port.cmi ocs_numstr.cmi ocs_num.cmi \
+ ocs_macro.cmi ocs_list.cmi ocs_lex.cmi ocs_io.cmi ocs_eval.cmi \
+ ocs_error.cmo ocs_env.cmi ocs_contin.cmi ocs_compile.cmi ocs_char.cmi \
+ ocs_top.cmi
+ocs_top.cmx: ocs_vector.cmx ocs_types.cmi ocs_string.cmx ocs_read.cmx \
+ ocs_print.cmx ocs_prim.cmx ocs_port.cmx ocs_numstr.cmx ocs_num.cmx \
+ ocs_macro.cmx ocs_list.cmx ocs_lex.cmx ocs_io.cmx ocs_eval.cmx \
+ ocs_error.cmx ocs_env.cmx ocs_contin.cmx ocs_compile.cmx ocs_char.cmx \
+ ocs_top.cmi
+ocs_vartable.cmo: ocs_vartable.cmi
+ocs_vartable.cmx: ocs_vartable.cmi
+ocs_vector.cmo: ocs_types.cmi ocs_error.cmo ocs_env.cmi ocs_vector.cmi
+ocs_vector.cmx: ocs_types.cmi ocs_error.cmx ocs_env.cmx ocs_vector.cmi
+ocs_wrap.cmo: ocs_types.cmi ocs_error.cmo
+ocs_wrap.cmx: ocs_types.cmi ocs_error.cmx
+ocs_char.cmi: ocs_types.cmi
+ocs_compile.cmi: ocs_types.cmi
+ocs_contin.cmi: ocs_types.cmi
+ocs_env.cmi: ocs_types.cmi ocs_sym.cmi
+ocs_eval.cmi: ocs_types.cmi
+ocs_io.cmi: ocs_types.cmi
+ocs_lex.cmi: ocs_types.cmi ocs_port.cmi ocs_error.cmo
+ocs_list.cmi: ocs_types.cmi
+ocs_macro.cmi: ocs_types.cmi
+ocs_misc.cmi: ocs_types.cmi
+ocs_num.cmi: ocs_types.cmi
+ocs_numaux.cmi: ocs_types.cmi
+ocs_numstr.cmi: ocs_types.cmi
+ocs_prim.cmi: ocs_types.cmi
+ocs_print.cmi: ocs_types.cmi ocs_port.cmi
+ocs_read.cmi: ocs_types.cmi ocs_port.cmi ocs_lex.cmi
+ocs_string.cmi: ocs_types.cmi
+ocs_sym.cmi: ocs_types.cmi
+ocs_top.cmi: ocs_types.cmi
+ocs_types.cmi: ocs_vartable.cmi ocs_port.cmi
+ocs_vector.cmi: ocs_types.cmi
@@ -0,0 +1,57 @@
+#
+# Build system for ocs library and interpreter
+#
+
+include Makefile.common
+
+BC_LIB = ocs.cma
+N_LIB = ocs.cmxa
+C_LIB = ocs.a
+INTERP = ocscm
+
+BC_OBJS = ocs_error.cmo ocs_port.cmo ocs_vartable.cmo ocs_sym.cmo \
+ ocs_env.cmo ocs_char.cmo ocs_complex.cmo ocs_numaux.cmo \
+ ocs_num.cmo ocs_numstr.cmo ocs_lex.cmo ocs_misc.cmo ocs_read.cmo \
+ ocs_eval.cmo ocs_compile.cmo ocs_contin.cmo ocs_print.cmo \
+ ocs_io.cmo ocs_list.cmo ocs_macro.cmo ocs_prim.cmo ocs_string.cmo \
+ ocs_vector.cmo ocs_wrap.cmo ocs_top.cmo
+
+N_OBJS = ocs_error.cmx ocs_sym.cmx ocs_vartable.cmx ocs_env.cmx \
+ ocs_char.cmx ocs_misc.cmx ocs_compile.cmx ocs_eval.cmx \
+ ocs_contin.cmx ocs_port.cmx ocs_complex.cmx ocs_numaux.cmx \
+ ocs_num.cmx ocs_numstr.cmx ocs_print.cmx ocs_lex.cmx ocs_read.cmx \
+ ocs_io.cmx ocs_list.cmx ocs_macro.cmx ocs_prim.cmx ocs_string.cmx \
+ ocs_vector.cmx ocs_wrap.cmx ocs_top.cmx
+
+INTERP_OBJS = ocs_main.cmx
+
+BCI_OBJS = ocs_main.cmo
+BCI = ocscm-bc
+
+all: $(BC_LIB) $(N_LIB) $(INTERP)
+
+native: $(N_LIB)
+
+bytecode: $(BC_LIB)
+
+$(N_LIB): $(N_OBJS)
+ $(OCAMLOPT) -a -o $(N_LIB) $(N_OBJS)
+
+$(BC_LIB): $(BC_OBJS)
+ $(OCAMLC) -a -o $(BC_LIB) $(BC_OBJS)
+
+$(INTERP): $(N_LIB) $(INTERP_OBJS)
+ $(OCAMLOPT) -o $(INTERP) nums.cmxa unix.cmxa $(N_LIB) $(INTERP_OBJS)
+
+$(BCI): $(BC_LIB) $(BCI_OBJS)
+ $(OCAMLC) $(OCAMLFLAGS) -o $(BCI) nums.cma unix.cma $(BC_LIB) $(BCI_OBJS)
+
+clean:
+ -rm -f $(N_LIB) $(BC_LIB) $(C_LIB) $(INTERP) *.cm* *.o
+ -rm -f $(BCI)
+
+depend:
+ $(OCAMLDEP) *.ml *.mli > .depend
+
+include .depend
+
Oops, something went wrong.

0 comments on commit d8e98ee

Please sign in to comment.