diff --git a/lib/ocaml/baseline/expected.json b/lib/ocaml/baseline/expected.json index 167d68c1..4d328b0d 100644 --- a/lib/ocaml/baseline/expected.json +++ b/lib/ocaml/baseline/expected.json @@ -1,6 +1,7 @@ { "closures.ml": 315, "exception_handle.ml": 4, + "expr_eval.ml": 16, "factorial.ml": 3628800, "list_ops.ml": 30, "module_use.ml": 3, diff --git a/lib/ocaml/baseline/expr_eval.ml b/lib/ocaml/baseline/expr_eval.ml new file mode 100644 index 00000000..59ee0e43 --- /dev/null +++ b/lib/ocaml/baseline/expr_eval.ml @@ -0,0 +1,19 @@ +(* Baseline: a tiny expression evaluator using ADTs + match *) +type expr = + | Lit of int + | Add of expr * expr + | Mul of expr * expr + | Neg of expr +;; + +let rec eval e = + match e with + | Lit n -> n + | Add (a, b) -> eval a + eval b + | Mul (a, b) -> eval a * eval b + | Neg x -> 0 - eval x +;; + +(* (1 + 2) * (3 + 4) - 5 = 21 - 5 = 16 *) +eval + (Add (Mul (Add (Lit 1, Lit 2), Add (Lit 3, Lit 4)), Neg (Lit 5))) diff --git a/lib/ocaml/baseline/run.sh b/lib/ocaml/baseline/run.sh index 6e62e688..8d5e75e7 100755 --- a/lib/ocaml/baseline/run.sh +++ b/lib/ocaml/baseline/run.sh @@ -36,7 +36,7 @@ for f in lib/ocaml/baseline/*.ml; do (eval "(ocaml-run-program (file-read \"$f\"))") EOF - output=$(timeout 60 "$SX_SERVER" < "$TMP" 2>/dev/null) + output=$(timeout 120 "$SX_SERVER" < "$TMP" 2>/dev/null) rm -f "$TMP" result=$(echo "$output" | awk ' diff --git a/plans/ocaml-on-sx.md b/plans/ocaml-on-sx.md index 44e30220..9e5ba3b5 100644 --- a/plans/ocaml-on-sx.md +++ b/plans/ocaml-on-sx.md @@ -377,6 +377,11 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means: _Newest first._ +- 2026-05-08 Phase 5.1 — expr_eval.ml baseline (9/9 pass). A tiny + arithmetic-expression evaluator using ADT (`type expr = Lit | Add | + Mul | Neg`) + recursive eval + pattern match — exercises the full + type-decl + ctor + match pipeline end-to-end. Per-program timeout + bumped to 120s in run.sh. - 2026-05-08 Phase 3 — polymorphic variants `` `Tag `` (+4 tests, 382 total). Tokenizer recognises backtick followed by an upper ident, tokenizing identically to nominal ctors. Parser and evaluator treat