forth: BASE/DECIMAL/HEX/BIN/OCTAL (+9; Hayes 174/590)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Has been cancelled

This commit is contained in:
2026-04-24 20:40:11 +00:00
parent 35ce18eb97
commit acf9c273a2
8 changed files with 76 additions and 9 deletions

View File

@@ -24,7 +24,7 @@
(forth-execute-word state w)
(forth-compile-call state tok))
(let
((n (forth-parse-number tok (get state "base"))))
((n (forth-parse-number tok (get (get state "vars") "base"))))
(if
(not (nil? n))
(forth-compile-lit state n)
@@ -219,7 +219,7 @@
(not (nil? w))
(forth-execute-word state w)
(let
((n (forth-parse-number tok (get state "base"))))
((n (forth-parse-number tok (get (get state "vars") "base"))))
(if
(not (nil? n))
(forth-push state n)

View File

@@ -87,8 +87,7 @@
"actual"
(str hayes-actual))))))))))
(forth-def-prim! state "TESTING" (fn (s) nil))
(forth-def-prim! state "HEX" (fn (s) (dict-set! s "base" 16)))
(forth-def-prim! state "DECIMAL" (fn (s) (dict-set! s "base" 10)))
;; HEX/DECIMAL are real primitives now (runtime.sx) — no stub needed.
state))
(define

View File

@@ -17,7 +17,7 @@
(not (nil? w))
(forth-execute-word state w)
(let
((n (forth-parse-number tok (get state "base"))))
((n (forth-parse-number tok (get (get state "vars") "base"))))
(if
(not (nil? n))
(forth-push state n)

View File

@@ -18,8 +18,8 @@
(dict-set! s "output" "")
(dict-set! s "compiling" false)
(dict-set! s "current-def" nil)
(dict-set! s "base" 10)
(dict-set! s "vars" (dict))
(dict-set! (get s "vars") "base" 10)
(dict-set! s "cstack" (list))
(dict-set! s "mem" (dict))
(dict-set! s "here" 0)
@@ -538,6 +538,23 @@
(> n 0)
(for-each (fn (_) (forth-emit-str s " ")) (range 0 n))))))
(forth-def-prim! state "BL" (fn (s) (forth-push s 32)))
(forth-def-prim!
state
"DECIMAL"
(fn (s) (dict-set! (get s "vars") "base" 10)))
(forth-def-prim!
state
"HEX"
(fn (s) (dict-set! (get s "vars") "base" 16)))
(forth-def-prim!
state
"BIN"
(fn (s) (dict-set! (get s "vars") "base" 2)))
(forth-def-prim!
state
"OCTAL"
(fn (s) (dict-set! (get s "vars") "base" 8)))
(forth-def-prim! state "BASE" (fn (s) (forth-push s "base")))
(forth-def-prim! state "I" (fn (s) (forth-push s (forth-rpeek s))))
(forth-def-prim!
state

View File

@@ -1,6 +1,6 @@
{
"source": "gerryjackson/forth2012-test-suite src/core.fr",
"generated_at": "2026-04-24T20:12:09Z",
"generated_at": "2026-04-24T20:39:51Z",
"chunks_available": 638,
"chunks_fed": 590,
"total": 590,

View File

@@ -11,7 +11,7 @@
| percent | 29% |
- **Source**: `gerryjackson/forth2012-test-suite` `src/core.fr`
- **Generated**: 2026-04-24T20:12:09Z
- **Generated**: 2026-04-24T20:39:51Z
- **Note**: completed
A "chunk" is any preprocessed segment ending at a `}T` (every Hayes test

View File

@@ -171,6 +171,47 @@
((r (forth-run "1000 2 ACCEPT")))
(let ((stk (nth r 2))) (forth-p4-assert "ACCEPT empty buf -> 0" (list 0) stk)))))
(define
forth-p4-base-tests
(fn
()
(forth-p4-check-top
"BASE default is 10"
"BASE @"
10)
(forth-p4-check-top
"HEX switches base to 16"
"HEX BASE @"
16)
(forth-p4-check-top
"DECIMAL resets to 10"
"HEX DECIMAL BASE @"
10)
(forth-p4-check-top
"HEX parses 10 as 16"
"HEX 10"
16)
(forth-p4-check-top
"HEX parses FF as 255"
"HEX FF"
255)
(forth-p4-check-top
"DECIMAL parses 10 as 10"
"HEX DECIMAL 10"
10)
(forth-p4-check-top
"BIN parses 1010 as 10"
"BIN 1010"
10)
(forth-p4-check-top
"OCTAL parses 17 as 15"
"OCTAL 17"
15)
(forth-p4-check-top
"BASE @ ; 16 BASE ! ; BASE @"
"BASE @ 16 BASE ! BASE @ SWAP DROP"
16)))
(define
forth-p4-run-all
(fn
@@ -185,6 +226,7 @@
(forth-p4-charplus-tests)
(forth-p4-char-tests)
(forth-p4-key-accept-tests)
(forth-p4-base-tests)
(dict
"passed"
forth-p4-passed