phase-22 JS: stdlib.sx bitwise/Map/Set/RegExp + 25 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 38s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 38s
lib/js/stdlib.sx (36 forms): - Bitwise ops (js-bitand/bitor/bitxor/lshift/rshift/urshift/bitnot) use truncate instead of js-num-to-int (which calls integer /0 and crashes). - Map class: dict-backed list-of-pairs with linear-scan find, mutable via dict-set!; js-map-new/get/set!/has/delete!/clear/keys/vals/entries/for-each. - Set class: backed by SX make-set primitive; set-member?/set-add!/set-remove! all take (set item) argument order — fixed from (item set) which threw. - RegExp: callable lambda wrapping js-regex-new (not a dict, so directly callable). - Wires Map/Set/RegExp into js-global. lib/js/test.sh: epochs 6000-6032 (25 tests) — all pass. Result: 492/585 tests pass (was 466/560 before this phase). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,6 +35,8 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(load "lib/js/runtime.sx")
|
||||
(epoch 6)
|
||||
(load "lib/js/regex.sx")
|
||||
(epoch 7)
|
||||
(load "lib/js/stdlib.sx")
|
||||
|
||||
;; ── Phase 0: stubs still behave ─────────────────────────────────
|
||||
(epoch 10)
|
||||
@@ -1427,6 +1429,64 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 5103)
|
||||
(eval "(js-tdz-check \"x\" 42)")
|
||||
|
||||
;; ── Phase 22: Bitwise ops ────────────────────────────────────────
|
||||
(epoch 6000)
|
||||
(eval "(js-bitand 5 3)")
|
||||
(epoch 6001)
|
||||
(eval "(js-bitor 5 3)")
|
||||
(epoch 6002)
|
||||
(eval "(js-bitxor 5 3)")
|
||||
(epoch 6003)
|
||||
(eval "(js-lshift 1 4)")
|
||||
(epoch 6004)
|
||||
(eval "(js-rshift 32 2)")
|
||||
(epoch 6005)
|
||||
(eval "(js-rshift -8 1)")
|
||||
(epoch 6006)
|
||||
(eval "(js-urshift 4294967292 2)")
|
||||
(epoch 6007)
|
||||
(eval "(js-bitnot 0)")
|
||||
|
||||
;; ── Phase 22: Map ─────────────────────────────────────────────────
|
||||
(epoch 6010)
|
||||
(eval "(js-map? (js-map-new))")
|
||||
(epoch 6011)
|
||||
(eval "(get (js-map-set! (js-map-new) \"k\" 42) \"size\")")
|
||||
(epoch 6012)
|
||||
(eval "(let ((m (js-map-new))) (js-map-set! m \"a\" 1) (js-map-get m \"a\"))")
|
||||
(epoch 6013)
|
||||
(eval "(let ((m (js-map-new))) (js-map-set! m \"x\" 9) (js-map-has m \"x\"))")
|
||||
(epoch 6014)
|
||||
(eval "(let ((m (js-map-new))) (js-map-set! m \"x\" 9) (js-map-has m \"y\"))")
|
||||
(epoch 6015)
|
||||
(eval "(let ((m (js-map-new))) (js-map-set! m \"a\" 1) (js-map-set! m \"b\" 2) (get m \"size\"))")
|
||||
(epoch 6016)
|
||||
(eval "(let ((m (js-map-new))) (js-map-set! m \"a\" 1) (js-map-delete! m \"a\") (get m \"size\"))")
|
||||
(epoch 6017)
|
||||
(eval "(let ((m (js-map-new))) (js-map-set! m \"a\" 1) (js-map-set! m \"a\" 99) (js-map-get m \"a\"))")
|
||||
|
||||
;; ── Phase 22: Set ─────────────────────────────────────────────────
|
||||
(epoch 6020)
|
||||
(eval "(js-set? (js-set-new))")
|
||||
(epoch 6021)
|
||||
(eval "(let ((s (js-set-new))) (js-set-add! s 1) (js-set-has s 1))")
|
||||
(epoch 6022)
|
||||
(eval "(let ((s (js-set-new))) (js-set-add! s 1) (js-set-has s 2))")
|
||||
(epoch 6023)
|
||||
(eval "(let ((s (js-set-new))) (js-set-add! s 1) (js-set-add! s 1) (get s \"size\"))")
|
||||
(epoch 6024)
|
||||
(eval "(let ((s (js-set-new))) (js-set-add! s 1) (js-set-add! s 2) (get s \"size\"))")
|
||||
(epoch 6025)
|
||||
(eval "(let ((s (js-set-new))) (js-set-add! s 1) (js-set-delete! s 1) (get s \"size\"))")
|
||||
|
||||
;; ── Phase 22: RegExp constructor ──────────────────────────────────
|
||||
(epoch 6030)
|
||||
(eval "(js-regex? (RegExp \"ab\" \"i\"))")
|
||||
(epoch 6031)
|
||||
(eval "(get (RegExp \"hello\" \"gi\") \"global\")")
|
||||
(epoch 6032)
|
||||
(eval "(get (RegExp \"foo\" \"i\") \"ignoreCase\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
|
||||
@@ -2188,6 +2248,39 @@ check 5101 "const binding initialized" '42'
|
||||
check 5102 "TDZ sentinel is detectable" 'true'
|
||||
check 5103 "tdz-check passes non-sentinel" '42'
|
||||
|
||||
# ── Phase 22: Bitwise ops ─────────────────────────────────────────
|
||||
check 6000 "bitand 5&3" '1'
|
||||
check 6001 "bitor 5|3" '7'
|
||||
check 6002 "bitxor 5^3" '6'
|
||||
check 6003 "lshift 1<<4" '16'
|
||||
check 6004 "rshift 32>>2" '8'
|
||||
check 6005 "rshift -8>>1" '-4'
|
||||
check 6006 "urshift >>>" '1073741823'
|
||||
check 6007 "bitnot ~0" '-1'
|
||||
|
||||
# ── Phase 22: Map ─────────────────────────────────────────────────
|
||||
check 6010 "map? new map" 'true'
|
||||
check 6011 "map set→size 1" '1'
|
||||
check 6012 "map get existing" '1'
|
||||
check 6013 "map has key yes" 'true'
|
||||
check 6014 "map has key no" 'false'
|
||||
check 6015 "map size 2 entries" '2'
|
||||
check 6016 "map delete→size 0" '0'
|
||||
check 6017 "map set overwrites" '99'
|
||||
|
||||
# ── Phase 22: Set ─────────────────────────────────────────────────
|
||||
check 6020 "set? new set" 'true'
|
||||
check 6021 "set has after add" 'true'
|
||||
check 6022 "set has absent" 'false'
|
||||
check 6023 "set dedup size" '1'
|
||||
check 6024 "set size 2" '2'
|
||||
check 6025 "set delete→size 0" '0'
|
||||
|
||||
# ── Phase 22: RegExp ──────────────────────────────────────────────
|
||||
check 6030 "RegExp? result" 'true'
|
||||
check 6031 "RegExp global flag" 'true'
|
||||
check 6032 "RegExp ignoreCase" 'true'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "✓ $PASS/$TOTAL JS-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user