js-on-sx: postfix + prefix ++/--
Parser: jp-parse-postfix emits (js-postfix op target) on trailing ++/--; jp-parse-primary emits (js-prefix op target) before the unary -/+/!/~ branch. Transpile: js-transpile-prefix → (set! name (+ (js-to-number name) ±1)) for idents, (js-set-prop obj key ...) for members/indices. js-transpile-postfix caches old value in a let binding, updates, returns the saved value. 340/342 unit (+11), 148/148 slice unchanged.
This commit is contained in:
@@ -875,6 +875,30 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 1208)
|
||||
(eval "(js-eval \"isFinite(1/0)\")")
|
||||
|
||||
;; ── Phase 11.incdec: ++ / -- ─────────────────────────────────────
|
||||
(epoch 1300)
|
||||
(eval "(js-eval \"var x = 5; x++; x\")")
|
||||
(epoch 1301)
|
||||
(eval "(js-eval \"var x = 5; var y = x++; y\")")
|
||||
(epoch 1302)
|
||||
(eval "(js-eval \"var x = 5; ++x\")")
|
||||
(epoch 1303)
|
||||
(eval "(js-eval \"var x = 5; var y = ++x; y\")")
|
||||
(epoch 1304)
|
||||
(eval "(js-eval \"var x = 5; x--; x\")")
|
||||
(epoch 1305)
|
||||
(eval "(js-eval \"var x = 5; --x\")")
|
||||
(epoch 1306)
|
||||
(eval "(js-eval \"var o = {n: 10}; o.n++; o.n\")")
|
||||
(epoch 1307)
|
||||
(eval "(js-eval \"var o = {n: 10}; ++o.n\")")
|
||||
(epoch 1308)
|
||||
(eval "(js-eval \"var a = [1,2,3]; a[1]++; a[1]\")")
|
||||
(epoch 1309)
|
||||
(eval "(js-eval \"var x = 5; for (var i = 0; i < 3; i++) x++; x\")")
|
||||
(epoch 1310)
|
||||
(eval "(js-eval \"var sum = 0; for (var i = 1; i <= 5; i++) sum = sum + i; sum\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1340,6 +1364,19 @@ check 1206 "Number.EPSILON > 0" 'true'
|
||||
check 1207 "isFinite(1)" 'true'
|
||||
check 1208 "isFinite(Inf)" 'false'
|
||||
|
||||
# ── Phase 11.incdec: ++ / -- ────────────────────────────────────
|
||||
check 1300 "x++ bumps x" '6'
|
||||
check 1301 "x++ returns old" '5'
|
||||
check 1302 "++x bumps and returns" '6'
|
||||
check 1303 "++x captured new" '6'
|
||||
check 1304 "x-- decrements" '4'
|
||||
check 1305 "--x decrements, returns new" '4'
|
||||
check 1306 "obj.n++" '11'
|
||||
check 1307 "++obj.n" '11'
|
||||
check 1308 "a[1]++" '3'
|
||||
check 1309 "for-loop x++" '8'
|
||||
check 1310 "for-loop accumulator" '15'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "✓ $PASS/$TOTAL JS-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user