forth: WITHIN/ABORT/ABORT"/EXIT/UNLOOP (+7; Hayes 486/638, 76%)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled
This commit is contained in:
@@ -122,6 +122,8 @@
|
|||||||
(forth-loop-step s op pc))
|
(forth-loop-step s op pc))
|
||||||
((and (dict? op) (= (get op "kind") "+loop"))
|
((and (dict? op) (= (get op "kind") "+loop"))
|
||||||
(forth-plusloop-step s op pc))
|
(forth-plusloop-step s op pc))
|
||||||
|
((and (dict? op) (= (get op "kind") "exit"))
|
||||||
|
(dict-set! pc "v" 1000000000))
|
||||||
(else (begin (op s) (dict-set! pc "v" (+ (get pc "v") 1)))))))
|
(else (begin (op s) (dict-set! pc "v" (+ (get pc "v") 1)))))))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
@@ -791,6 +793,69 @@
|
|||||||
(let
|
(let
|
||||||
((w (forth-pop s)))
|
((w (forth-pop s)))
|
||||||
(forth-push s (or (get w "body-addr") 0)))))
|
(forth-push s (or (get w "body-addr") 0)))))
|
||||||
|
(forth-def-prim!
|
||||||
|
state
|
||||||
|
"WITHIN"
|
||||||
|
(fn
|
||||||
|
(s)
|
||||||
|
(let
|
||||||
|
((n3 (forth-pop s)) (n2 (forth-pop s)) (n1 (forth-pop s)))
|
||||||
|
(let
|
||||||
|
((a (forth-to-unsigned (- n1 n2) 32))
|
||||||
|
(b (forth-to-unsigned (- n3 n2) 32)))
|
||||||
|
(forth-push s (if (< a b) -1 0))))))
|
||||||
|
(forth-def-prim!
|
||||||
|
state
|
||||||
|
"ABORT"
|
||||||
|
(fn
|
||||||
|
(s)
|
||||||
|
(dict-set! s "dstack" (list))
|
||||||
|
(dict-set! s "rstack" (list))
|
||||||
|
(dict-set! s "cstack" (list))
|
||||||
|
(forth-error s "ABORT")))
|
||||||
|
(forth-def-prim-imm!
|
||||||
|
state
|
||||||
|
"ABORT\""
|
||||||
|
(fn
|
||||||
|
(s)
|
||||||
|
(let
|
||||||
|
((msg (forth-parse-quote s)))
|
||||||
|
(if
|
||||||
|
(get s "compiling")
|
||||||
|
(forth-def-append!
|
||||||
|
s
|
||||||
|
(fn
|
||||||
|
(ss)
|
||||||
|
(when
|
||||||
|
(not (= (forth-pop ss) 0))
|
||||||
|
(begin
|
||||||
|
(dict-set! ss "dstack" (list))
|
||||||
|
(dict-set! ss "rstack" (list))
|
||||||
|
(dict-set! ss "cstack" (list))
|
||||||
|
(forth-error ss (str "ABORT: " msg))))))
|
||||||
|
(when
|
||||||
|
(not (= (forth-pop s) 0))
|
||||||
|
(begin
|
||||||
|
(dict-set! s "dstack" (list))
|
||||||
|
(dict-set! s "rstack" (list))
|
||||||
|
(dict-set! s "cstack" (list))
|
||||||
|
(forth-error s (str "ABORT: " msg))))))))
|
||||||
|
(forth-def-prim-imm!
|
||||||
|
state
|
||||||
|
"EXIT"
|
||||||
|
(fn
|
||||||
|
(s)
|
||||||
|
(when
|
||||||
|
(not (get s "compiling"))
|
||||||
|
(forth-error s "EXIT outside definition"))
|
||||||
|
(let
|
||||||
|
((op (dict)))
|
||||||
|
(dict-set! op "kind" "exit")
|
||||||
|
(forth-def-append! s op))))
|
||||||
|
(forth-def-prim!
|
||||||
|
state
|
||||||
|
"UNLOOP"
|
||||||
|
(fn (s) (forth-rpop s) (forth-rpop s)))
|
||||||
(forth-def-prim-imm!
|
(forth-def-prim-imm!
|
||||||
state
|
state
|
||||||
"["
|
"["
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"source": "gerryjackson/forth2012-test-suite src/core.fr",
|
"source": "gerryjackson/forth2012-test-suite src/core.fr",
|
||||||
"generated_at": "2026-04-25T01:22:10Z",
|
"generated_at": "2026-04-25T01:55:16Z",
|
||||||
"chunks_available": 638,
|
"chunks_available": 638,
|
||||||
"chunks_fed": 638,
|
"chunks_fed": 638,
|
||||||
"total": 638,
|
"total": 638,
|
||||||
"pass": 477,
|
"pass": 486,
|
||||||
"fail": 14,
|
"fail": 14,
|
||||||
"error": 147,
|
"error": 138,
|
||||||
"percent": 74,
|
"percent": 76,
|
||||||
"note": "completed"
|
"note": "completed"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
| chunks available | 638 |
|
| chunks available | 638 |
|
||||||
| chunks fed | 638 |
|
| chunks fed | 638 |
|
||||||
| total | 638 |
|
| total | 638 |
|
||||||
| pass | 477 |
|
| pass | 486 |
|
||||||
| fail | 14 |
|
| fail | 14 |
|
||||||
| error | 147 |
|
| error | 138 |
|
||||||
| percent | 74% |
|
| percent | 76% |
|
||||||
|
|
||||||
- **Source**: `gerryjackson/forth2012-test-suite` `src/core.fr`
|
- **Source**: `gerryjackson/forth2012-test-suite` `src/core.fr`
|
||||||
- **Generated**: 2026-04-25T01:22:10Z
|
- **Generated**: 2026-04-25T01:55:16Z
|
||||||
- **Note**: completed
|
- **Note**: completed
|
||||||
|
|
||||||
A "chunk" is any preprocessed segment ending at a `}T` (every Hayes test
|
A "chunk" is any preprocessed segment ending at a `}T` (every Hayes test
|
||||||
|
|||||||
@@ -226,6 +226,27 @@
|
|||||||
": A 100 ; : B S\" A\" EVALUATE ; B"
|
": A 100 ; : B S\" A\" EVALUATE ; B"
|
||||||
100)))
|
100)))
|
||||||
|
|
||||||
|
(define
|
||||||
|
forth-p5-misc-tests
|
||||||
|
(fn
|
||||||
|
()
|
||||||
|
(forth-p5-check-top "WITHIN inclusive lower" "3 2 10 WITHIN" -1)
|
||||||
|
(forth-p5-check-top "WITHIN exclusive upper" "10 2 10 WITHIN" 0)
|
||||||
|
(forth-p5-check-top "WITHIN below range" "1 2 10 WITHIN" 0)
|
||||||
|
(forth-p5-check-top "WITHIN at lower" "2 2 10 WITHIN" -1)
|
||||||
|
(forth-p5-check-top
|
||||||
|
"EXIT leaves colon-def early"
|
||||||
|
": F 5 EXIT 99 ; F"
|
||||||
|
5)
|
||||||
|
(forth-p5-check-stack
|
||||||
|
"EXIT in IF branch"
|
||||||
|
": F 5 0 IF DROP 99 EXIT THEN ; F"
|
||||||
|
(list 5))
|
||||||
|
(forth-p5-check-top
|
||||||
|
"UNLOOP + EXIT in DO"
|
||||||
|
": SUM 0 10 0 DO I 5 = IF I UNLOOP EXIT THEN LOOP ; SUM"
|
||||||
|
5)))
|
||||||
|
|
||||||
(define
|
(define
|
||||||
forth-p4-check-output-passthrough
|
forth-p4-check-output-passthrough
|
||||||
(fn
|
(fn
|
||||||
@@ -247,6 +268,7 @@
|
|||||||
(forth-p5-format-tests)
|
(forth-p5-format-tests)
|
||||||
(forth-p5-dict-tests)
|
(forth-p5-dict-tests)
|
||||||
(forth-p5-state-tests)
|
(forth-p5-state-tests)
|
||||||
|
(forth-p5-misc-tests)
|
||||||
(dict
|
(dict
|
||||||
"passed"
|
"passed"
|
||||||
forth-p5-passed
|
forth-p5-passed
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ Representation:
|
|||||||
- [x] Number formatting: `<#`, `#`, `#S`, `#>`, `HOLD`, `SIGN`, `.R`, `U.`, `U.R`
|
- [x] Number formatting: `<#`, `#`, `#S`, `#>`, `HOLD`, `SIGN`, `.R`, `U.`, `U.R`
|
||||||
- [x] Parsing/dictionary: `WORD`, `FIND`, `EXECUTE`, `'`, `[']`, `LITERAL`, `POSTPONE`, `>BODY` (DOES> deferred — needs runtime-rebind of last CREATE)
|
- [x] Parsing/dictionary: `WORD`, `FIND`, `EXECUTE`, `'`, `[']`, `LITERAL`, `POSTPONE`, `>BODY` (DOES> deferred — needs runtime-rebind of last CREATE)
|
||||||
- [x] Source/state: `EVALUATE`, `STATE`, `[`, `]` (`SOURCE`/`>IN` stubbed; tokenized input means the exact byte/offset semantics aren't useful here)
|
- [x] Source/state: `EVALUATE`, `STATE`, `[`, `]` (`SOURCE`/`>IN` stubbed; tokenized input means the exact byte/offset semantics aren't useful here)
|
||||||
- [ ] Misc Core: `WITHIN`, `MAX`/`MIN` (already), `ABORT`, `ABORT"`, `EXIT`, `UNLOOP`
|
- [x] Misc Core: `WITHIN`, `MAX`/`MIN` (already), `ABORT`, `ABORT"`, `EXIT`, `UNLOOP`
|
||||||
- [ ] File Access word set (via SX IO)
|
- [ ] File Access word set (via SX IO)
|
||||||
- [ ] String word set (`SLITERAL`, `COMPARE`, `SEARCH`)
|
- [ ] String word set (`SLITERAL`, `COMPARE`, `SEARCH`)
|
||||||
- [ ] Target: 100% Hayes Core
|
- [ ] Target: 100% Hayes Core
|
||||||
@@ -106,6 +106,17 @@ Representation:
|
|||||||
|
|
||||||
_Newest first._
|
_Newest first._
|
||||||
|
|
||||||
|
- **Phase 5 — `WITHIN`/`ABORT`/`ABORT"`/`EXIT`/`UNLOOP` (+7;
|
||||||
|
Hayes 477→486, 76%).** `WITHIN` uses the ANS two's-complement
|
||||||
|
trick: `(n1-n2) U< (n3-n2)`. `ABORT` wipes the data/return/control
|
||||||
|
stacks and raises — the conformance runner catches it at the
|
||||||
|
chunk boundary. `ABORT"` parses its message like `S"`, then at
|
||||||
|
runtime pops a flag and raises only if truthy. `EXIT` adds a new
|
||||||
|
`:kind "exit"` op that the PC-driven body runner treats as a
|
||||||
|
jump-to-end; added a matching cond clause in `forth-step-op`.
|
||||||
|
`UNLOOP` pops two from the return stack — usable paired with
|
||||||
|
`EXIT` to bail from inside `DO`/`LOOP`.
|
||||||
|
|
||||||
- **Phase 5 — `[`, `]`, `STATE`, `EVALUATE` (+5; Hayes 463→477, 74%).**
|
- **Phase 5 — `[`, `]`, `STATE`, `EVALUATE` (+5; Hayes 463→477, 74%).**
|
||||||
`[` (IMMEDIATE) clears `state.compiling`, `]` sets it. `STATE`
|
`[` (IMMEDIATE) clears `state.compiling`, `]` sets it. `STATE`
|
||||||
pushes the sentinel address `"@@state"` and `@` reads it as
|
pushes the sentinel address `"@@state"` and `@` reads it as
|
||||||
|
|||||||
Reference in New Issue
Block a user