ocaml: phase 1+6 Buffer + parser !x in app args (+3 tests, 425 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 48s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 48s
Parser fix: at-app-start? and parse-app's loop recognise prefix ! as a deref of the next app arg. So 'List.rev !b' parses as '(:app List.rev (:deref b))' instead of stalling at !. Buffer module backed by a ref holding string list: create _ = ref [] add_string b s = b := s :: !b contents b = String.concat "" (List.rev !b) add_char/length/clear/reset
This commit is contained in:
@@ -167,7 +167,7 @@
|
|||||||
((= tt "ctor") true)
|
((= tt "ctor") true)
|
||||||
((and (= tt "keyword") (or (= tv "true") (= tv "false")))
|
((and (= tt "keyword") (or (= tv "true") (= tv "false")))
|
||||||
true)
|
true)
|
||||||
((and (= tt "op") (or (= tv "(") (= tv "[") (= tv "{"))) true)
|
((and (= tt "op") (or (= tv "(") (= tv "[") (= tv "{") (= tv "!"))) true)
|
||||||
(else false)))))
|
(else false)))))
|
||||||
(set!
|
(set!
|
||||||
parse-pattern-atom
|
parse-pattern-atom
|
||||||
@@ -532,7 +532,7 @@
|
|||||||
((= tt "ctor") true)
|
((= tt "ctor") true)
|
||||||
((and (= tt "keyword") (or (= tv "true") (= tv "false") (= tv "begin")))
|
((and (= tt "keyword") (or (= tv "true") (= tv "false") (= tv "begin")))
|
||||||
true)
|
true)
|
||||||
((and (= tt "op") (or (= tv "(") (= tv "[") (= tv "{"))) true)
|
((and (= tt "op") (or (= tv "(") (= tv "[") (= tv "{") (= tv "!"))) true)
|
||||||
(else false)))))
|
(else false)))))
|
||||||
(define parse-atom-postfix
|
(define parse-atom-postfix
|
||||||
(fn ()
|
(fn ()
|
||||||
@@ -568,7 +568,12 @@
|
|||||||
(when
|
(when
|
||||||
(at-app-start?)
|
(at-app-start?)
|
||||||
(let
|
(let
|
||||||
((arg (parse-atom-postfix)))
|
((arg
|
||||||
|
(cond
|
||||||
|
((at-op? "!")
|
||||||
|
(begin (advance-tok!)
|
||||||
|
(list :deref (parse-atom-postfix))))
|
||||||
|
(else (parse-atom-postfix)))))
|
||||||
(begin (set! head (list :app head arg)) (loop))))))
|
(begin (set! head (list :app head arg)) (loop))))))
|
||||||
(loop)
|
(loop)
|
||||||
head))))
|
head))))
|
||||||
|
|||||||
@@ -366,6 +366,16 @@
|
|||||||
let printf fmt = print_string fmt
|
let printf fmt = print_string fmt
|
||||||
end ;;
|
end ;;
|
||||||
|
|
||||||
|
module Buffer = struct
|
||||||
|
let create _ = ref []
|
||||||
|
let add_string b s = b := s :: !b
|
||||||
|
let add_char b c = b := c :: !b
|
||||||
|
let contents b = String.concat \"\" (List.rev !b)
|
||||||
|
let length b = String.length (String.concat \"\" (List.rev !b))
|
||||||
|
let clear b = b := []
|
||||||
|
let reset = clear
|
||||||
|
end ;;
|
||||||
|
|
||||||
module Sys = struct
|
module Sys = struct
|
||||||
let os_type = \"SX\"
|
let os_type = \"SX\"
|
||||||
let word_size = 64
|
let word_size = 64
|
||||||
|
|||||||
@@ -1044,6 +1044,14 @@ cat > "$TMPFILE" << 'EPOCHS'
|
|||||||
(epoch 3403)
|
(epoch 3403)
|
||||||
(eval "(ocaml-run-program \"module IntOrd = struct let compare a b = compare a b end ;; module IntSet = Set.Make(IntOrd) ;; let a = IntSet.add 1 (IntSet.add 2 (IntSet.add 3 IntSet.empty)) ;; let b = IntSet.add 2 (IntSet.add 3 (IntSet.add 4 IntSet.empty)) ;; IntSet.elements (IntSet.inter a b)\")")
|
(eval "(ocaml-run-program \"module IntOrd = struct let compare a b = compare a b end ;; module IntSet = Set.Make(IntOrd) ;; let a = IntSet.add 1 (IntSet.add 2 (IntSet.add 3 IntSet.empty)) ;; let b = IntSet.add 2 (IntSet.add 3 (IntSet.add 4 IntSet.empty)) ;; IntSet.elements (IntSet.inter a b)\")")
|
||||||
|
|
||||||
|
;; ── Buffer module ──────────────────────────────────────────────
|
||||||
|
(epoch 3500)
|
||||||
|
(eval "(ocaml-run-program \"let b = Buffer.create 16 ;; Buffer.add_string b \\\"Hello\\\" ;; Buffer.add_string b \\\", \\\" ;; Buffer.add_string b \\\"World\\\" ;; Buffer.contents b\")")
|
||||||
|
(epoch 3501)
|
||||||
|
(eval "(ocaml-run-program \"let b = Buffer.create 16 ;; Buffer.add_string b \\\"abc\\\" ;; Buffer.length b\")")
|
||||||
|
(epoch 3502)
|
||||||
|
(eval "(ocaml-run-program \"let b = Buffer.create 16 ;; Buffer.add_string b \\\"x\\\" ;; Buffer.clear b ;; Buffer.contents b\")")
|
||||||
|
|
||||||
EPOCHS
|
EPOCHS
|
||||||
|
|
||||||
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||||
@@ -1652,6 +1660,11 @@ check 3401 "Map.is_empty false" 'false'
|
|||||||
check 3402 "Set.union" '(1 2 3)'
|
check 3402 "Set.union" '(1 2 3)'
|
||||||
check 3403 "Set.inter" '(2 3)'
|
check 3403 "Set.inter" '(2 3)'
|
||||||
|
|
||||||
|
# ── Buffer module ──────────────────────────────────────────────
|
||||||
|
check 3500 "Buffer concat 'Hello, World'" '"Hello, World"'
|
||||||
|
check 3501 "Buffer.length 3" '3'
|
||||||
|
check 3502 "Buffer.clear empties" '""'
|
||||||
|
|
||||||
TOTAL=$((PASS + FAIL))
|
TOTAL=$((PASS + FAIL))
|
||||||
if [ $FAIL -eq 0 ]; then
|
if [ $FAIL -eq 0 ]; then
|
||||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||||
|
|||||||
@@ -264,6 +264,9 @@ SX CEK evaluator (both JS and OCaml hosts)
|
|||||||
- [~] `Hashtbl`: `create`, `add`, `find`, `find_opt`, `replace`, `mem`,
|
- [~] `Hashtbl`: `create`, `add`, `find`, `find_opt`, `replace`, `mem`,
|
||||||
`length`. Backed by a one-element list cell holding a SX dict;
|
`length`. Backed by a one-element list cell holding a SX dict;
|
||||||
keys coerced to strings via `str` for polymorphic-key support.
|
keys coerced to strings via `str` for polymorphic-key support.
|
||||||
|
- [~] `Buffer`: `create`, `add_string`, `add_char`, `contents`, `length`,
|
||||||
|
`clear`, `reset`. Backed by a ref holding a list of strings; reverse +
|
||||||
|
`String.concat` on `contents`. Mostly-OCaml impl.
|
||||||
- [~] `Sys`: `os_type` (`"SX"`), `word_size`, `max_array_length`,
|
- [~] `Sys`: `os_type` (`"SX"`), `word_size`, `max_array_length`,
|
||||||
`max_string_length`, `executable_name`, `big_endian`, `unix`,
|
`max_string_length`, `executable_name`, `big_endian`, `unix`,
|
||||||
`win32`, `cygwin`. Constants only; `argv`/`getenv_opt`/`command`
|
`win32`, `cygwin`. Constants only; `argv`/`getenv_opt`/`command`
|
||||||
@@ -386,6 +389,11 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
|
|||||||
|
|
||||||
_Newest first._
|
_Newest first._
|
||||||
|
|
||||||
|
- 2026-05-08 Phase 1+6 — Buffer module + parser fix for `f !x` (+3
|
||||||
|
tests, 425 total). Parser: at-app-start? and parse-app's loop now
|
||||||
|
recognise `!` as the prefix-deref of an application argument, so
|
||||||
|
`String.concat "" (List.rev !b)` parses as `(... (deref b))`. Buffer
|
||||||
|
uses a ref holding a string list; contents reverses and concats.
|
||||||
- 2026-05-08 Phase 5.1 — word_count.ml baseline (10/10 pass). Uses
|
- 2026-05-08 Phase 5.1 — word_count.ml baseline (10/10 pass). Uses
|
||||||
Map.Make(StrOrd) + List.fold_left to count word frequencies; tests
|
Map.Make(StrOrd) + List.fold_left to count word frequencies; tests
|
||||||
the full functor pipeline with a real OCaml idiom.
|
the full functor pipeline with a real OCaml idiom.
|
||||||
|
|||||||
Reference in New Issue
Block a user