(defun ez-mem-ref-byte (addr)
(aref ez-memory addr))
+(defun ez-mem-ref-bytes (addr count)
+ (mapcar (lambda (offset) (ez-mem-ref-byte (+ addr offset)))
+ (number-sequence 0 (- count 1))))
+
(defun ez-mem-set-byte (addr val)
(aset ez-memory addr val))
(ez-mem-set-byte (+ addr i) (elt vals i))))
(defun ez-mem-ref-word (addr)
- (+ (* 256 (aref ez-memory addr))
- (aref ez-memory (+ addr 1))))
+ (logior (lsh (aref ez-memory addr) 8)
+ (aref ez-memory (+ addr 1))))
+
+(defun ez-mem-ref-words (addr count)
+ (mapcar (lambda (offset) (ez-mem-ref-word (+ addr offset)))
+ (number-sequence 0 (- (* 2 count) 1) 2)))
(defun ez-mem-set-word (addr val)
(let ((byte-high (/ val 256))
(logand (lsh word -5) #b11111)
(logand word #b11111)))
+(defun ez-make-zstring-word (zchar-triple)
+ (let ((c1 (elt zchar-triple 0))
+ (c2 (elt zchar-triple 1))
+ (c3 (elz zchar-triple 2)))
+ (logand )))
+
(defun ez-get-zstring-chars-and-length (base-addr)
(let ((addr base-addr)
(chars nil)
(defun ez-encode (string)
"Encodes a string as a 2-word 5-padded Z-string.
-Used for matching input with dictionary entries when tokenizing."
+Used for matching input with dictionary entries when tokenizing.
+Returns a length-2 list of words for comparison with a dictionary entry."
(let ((chars
(mapcan
(lambda (c)
(t
(list 5 6 (lsh c -5) (logand c #b11111)))))
string)))
- (if (< (length chars) 6)
- (append chars (make-list (- 6 (length chars)) 5))
- (take 6 chars))))
+ (let* ((zstring-chars
+ (if (< (length chars) 6)
+ (append chars (make-list (- 6 (length chars)) 5))
+ (take 6 chars)))
+ (c1 (elt zstring-chars 0))
+ (c2 (elt zstring-chars 1))
+ (c3 (elt zstring-chars 2))
+ (c4 (elt zstring-chars 3))
+ (c5 (elt zstring-chars 4))
+ (c6 (elt zstring-chars 5)))
+ (list
+ (logior (lsh c1 10)
+ (lsh c2 5)
+ c3)
+ (logior (lsh 1 15)
+ (lsh c4 10)
+ (lsh c5 5)
+ c6)))))
;; Dictionary
(> nseps 0)))
(defun ez-lookup-dictionary (text)
- (let ((encoded-text (ez-encode text))
- (nseps (ez-mem-ref-byte ez-dict-base))
- (bytes-per-entry (ez-mem-ref-byte (+ ez-dict-base 1 nseps)))
- (nentries (ez-mem-ref-word (+ ez-dict-base 2 nseps)))
- (entries-seen 0)
- (this-entry (+ ez-dict-base nseps 4)))
+ (let* ((encoded-text (ez-encode text))
+ (nseps (ez-mem-ref-byte ez-dict-base))
+ (bytes-per-entry (ez-mem-ref-byte (+ ez-dict-base 1 nseps)))
+ (nentries (ez-mem-ref-word (+ ez-dict-base 2 nseps)))
+ (entries-seen 0)
+ (this-entry (+ ez-dict-base nseps 4)))
(while (and (< entries-seen nentries)
(not (equal
- (ez-mem-ref-bytes this-entry 4)
+ (ez-mem-ref-words this-entry 2)
encoded-text)))
(setq entries-seen (+ entries-seen 1))
(setq this-entry (+ this-entry bytes-per-entry)))
(ez-mem-set-byte (+ baddr1 1 i) char)))
(ez-mem-set-byte (+ baddr1 1 (length input-string)) 0)
- (ez--tokenize baddr1 baddr2)))
+ (ez--tokenize baddr1 baddr2))
+ 'run)
(defun ez--tokenize (tb-baddr pb-baddr)
(while unfinished
(let ((next-char (ez-mem-ref-byte (+ tb-baddr 1 token-end))))
(cond
- ((eq char ?\s)
+ ((eq next-char ?\s)
;; Add token
(setq token-end (- token-end 1))
(let* ((text (ez-mem-ref-string (+ tb-baddr 1 token-start)
(defun ez-load-and-run (filename)
(ez-load-file filename)
(ez-parse-header)
- (ez-parse-dictionary)
(setq ez-call-stack (list (ez-make-call-stack-frame ez-start-pc)))
(ez-run))