···44small, embeddable R7RS Scheme implementation.
5566chibi-ocaml lets you embed one or more sandboxed Scheme virtual machines in your
77-OCaml programs. The chibi-scheme runtime is vendored and compiled automatically
88--- no system-level installation of chibi-scheme is required. But a C compiler capable of building chibi-scheme is required.
77+OCaml programs. The chibi-scheme runtime is vendored and compiled automatically,
88+so no system-level installation of chibi-scheme is required. A C compiler capable
99+of building chibi-scheme is still required.
9101011## Features
11121212-- **Full R7RS Scheme** -- the complete chibi-scheme 0.12.0 interpreter
1313+- **Embedded chibi-scheme runtime** -- based on vendored chibi-scheme 0.12.0 sources
1314- **Multiple independent VMs** -- each `Context.t` has its own heap
1415- **Configurable memory limits** -- set initial and maximum heap sizes
1516- **Capability-based sandboxing** -- whitelist file, network, process, and I/O access
···3132git clone https://github.com/username/chibi-ocaml.git
3233cd chibi-ocaml
3334dune build
3434-dune runtest # 97 binding tests + chibi's own 8000+ tests
3535+dune runtest
3536```
3737+3838+## Running Upstream chibi Tests
3939+4040+The repository includes a runner for executing upstream `chibi-scheme` test
4141+files through the OCaml bindings.
4242+4343+If you have an upstream checkout at `~/data/src/chibi-scheme`, run:
4444+4545+```sh
4646+dune exec test_runner/run_chibi_tests.exe
4747+```
4848+4949+The runner looks for tests in this order:
5050+5151+- `CHIBI_TEST_ROOT`
5252+- `~/data/src/chibi-scheme`
5353+- `vendor/chibi-scheme`
5454+5555+To point at a different checkout:
5656+5757+```sh
5858+CHIBI_TEST_ROOT=/path/to/chibi-scheme dune exec test_runner/run_chibi_tests.exe
5959+```
6060+6161+This runner is intended to compare embedded behavior with native
6262+`chibi-scheme` on the same test files. If a suite fails, check whether it also
6363+fails in the upstream checkout before treating it as a bindings regression.
36643765## Quick Start
3866
+1-1
chibi-ocaml.opam
···11# This file is generated by dune, edit dune-project instead
22opam-version: "2.0"
33-version: "0.1.0"
33+version: "0.1.1"
44synopsis: "OCaml bindings for chibi-scheme, an embeddable R7RS Scheme VM"
55description:
66 "chibi-ocaml provides OCaml bindings to the chibi-scheme interpreter, allowing you to embed one or more sandboxed Scheme VMs in your OCaml programs. Features include configurable memory limits, capability-based sandboxing, effect-based streaming, and full R7RS support. The chibi-scheme runtime is vendored and compiled automatically - no system installation required."
···234234 try Chibi_ffi.env_define ctx name void with _ -> ()
235235 ) names
236236237237- (** Install sandbox restrictions by overriding dangerous bindings with
238238- void and redirecting I/O ports.
239239-240240- The sandbox enforces restrictions on the interaction environment after
241241- the standard library has been loaded. Each capability that is NOT
242242- granted causes the corresponding bindings to be replaced with void.
243243-244244- This covers bindings from (scheme base), (scheme file),
245245- (chibi filesystem), (chibi process), (chibi net), (chibi system),
246246- (chibi shell), (scheme process-context), (scheme eval), (scheme load),
247247- and related modules. *)
237237+ (** Install sandbox restrictions by overriding selected bindings with void
238238+ and redirecting I/O ports. *)
248239 let apply_sandbox (t : t) =
249240 let sandbox = t.sandbox in
250241 let ctx = t.raw in
+4-11
test_runner/run_chibi_tests.ml
···11-(** Run the chibi-scheme test suites through our OCaml bindings.
22-33- This program exercises the full chibi-scheme test infrastructure
44- through the chibi-ocaml library, verifying that the embedded VM
55- can correctly execute all the standard tests. *)
11+(** Run selected upstream chibi-scheme test suites through the OCaml bindings. *)
6273open Chibi_ocaml.Chibi
84module Ffi = Chibi_ocaml.Chibi_ffi
···4339let tests_dir = Filename.concat test_root "tests"
4440let lib_dir = Filename.concat test_root "lib"
45414646-(** Create a context suitable for running tests.
4747- Full access, with module path pointing at vendored lib. *)
4242+(** Create a context suitable for running tests. *)
4843let make_test_context ?(max_heap = 64 * 1024 * 1024) () =
4944 Unix.putenv "CHIBI_MODULE_PATH" lib_dir;
5045 let config = Context.{
···6459let eval_capturing_output ctx code =
6560 Io.capture ctx (fun () -> Eval.string ctx code)
66616767-(** Load a .scm file and capture its output.
6868- Uses load_direct to properly handle top-level import forms. *)
6262+(** Load a .scm file and capture its output. *)
6963let load_capturing_output ctx file =
7064 Io.capture ctx (fun () -> Eval.load_direct ctx file)
71657272-(** Evaluate multi-expression code by writing to a temp file and loading.
7373- This properly handles import and other top-level forms. *)
6666+(** Evaluate multi-expression code by writing to a temp file and loading. *)
7467let eval_multi_capturing_output ctx code =
7568 let tmpfile = Filename.temp_file "chibi_test_" ".scm" in
7669 Fun.protect ~finally:(fun () -> Sys.remove tmpfile) (fun () ->