new-s
(binformat d new-s))))
+(defun ez-list-to-string-hex (l)
+ (concat "("
+ (when l
+ (concat
+ (format "%x" (car l))
+ (apply 'concat (mapcar (lambda (n) (format " %x" n)) (cdr l)))))
+ ")"))
+
;; Memory
(defvar ez-memory nil
(defun ez-get-global-var (gvar)
(if (> gvar 239)
(error "Invalid global variable %d" gvar))
- (ez-mem-ref-word (+ (* 2 gvar) ez-globalvartab-addr)))
+ (let ((val
+ (ez-mem-ref-word (+ (* 2 gvar) ez-globalvartab-addr))))
+ (message "\tRetrieved %x from global variable %x" val gvar)
+ val))
(defun ez-set-global-var (gvar val)
- (ez-mem-set-word (+ (* 2 gvar) ez-globalvartab-addr) val))
+ (ez-mem-set-word (+ (* 2 gvar) ez-globalvartab-addr) val)
+ (message "\tSet global variabl %x to %x" gvar val))
;; Object tree
(defun ez-routine-stack-push (val)
(let ((frame (car ez-call-stack)))
+ (message "\tPushed %x to stack" val)
(setf (elt frame 1) (cons val (elt frame 1)))))
(defun ez-routine-stack-pop ()
(let* ((frame (car ez-call-stack))
(rs-head (car (elt frame 1))))
(setf (elt frame 1) (cdr (elt frame 1)))
+ (message "\tPopped %x from stack" rs-head)
rs-head))
(defun ez-get-local-var (lvar)
- (let ((frame (car ez-call-stack)))
- (aref (elt frame 2) (- lvar 1))))
+ (let* ((frame (car ez-call-stack))
+ (val (aref (elt frame 2) (- lvar 1))))
+ (message "\tRetrieved value %x from local variable %x" val lvar)
+ val))
(defun ez-set-local-var (lvar val)
(let ((frame (car ez-call-stack)))
+ (message "\tSet local variable %x to %x" lvar val)
(aset (elt frame 2) (- lvar 1) val)))
(defun ez-get-pc ()
(let ((table-row (assoc (list optype opcode) ez-op-table)))
(unless table-row
(error "Unsupported op PC:%x Optype:%s Opcode:%x Operands:%s Operand-types:%s"
- instr-pc optype opcode operands operand-types))
+ instr-pc optype opcode (ez-list-to-string-hex operands) operand-types))
(let ((mnemonic (elt table-row 1)))
(message "PC:%x Optype:%s Opcode:%x Mnemonic:%s Operands:%s Operand-types:%s"
- instr-pc optype opcode mnemonic operands operand-types))
+ instr-pc optype opcode mnemonic
+ (ez-list-to-string-hex operands) operand-types))
(funcall (elt table-row 2) operands operand-types))))
(defun ez-read-var-operands-and-inc ()
(if (= type1 #b11)
nil
(cons type1
- (let ((type2 (lsh (logand #b110000 type-byte) -4)))
+ (let ((type2 (mod (lsh type-byte -4) 4)))
(if (= type2 #b11)
nil
(cons type2
- (let ((type3 (lsh (logand #b1100 type-byte) -2)))
+ (let ((type3 (mod (lsh type-byte -2) 4)))
(if (= type3 #b11)
nil
(cons type3
- (let ((type4 (logand #b11)))
+ (let ((type4 (mod type-byte 4)))
(if (= type4 #b11)
nil
(list type4))))))))))))))
((2op #x16) mul ez-op-mul)
((2op #x17) div ez-op-div)
((2op #x18) mod ez-op-mod)
- ((var #x00) call_fv ez-op-callf)
+ ((var #x00) call_fv ez-op-callfv)
((1op #x01) get_sibling ez-op-get-sibling)
((1op #x02) get_child ez-op-get-child)
((1op #x03) get_parent ez-op-get-parent)
(defun ez-op-ret (operands &optional operand-types)
(let ((retval (car operands)))
+ (message "\tReturning value %x" retval)
(ez-pop-call-stack-frame)
(ez-set-var (ez-read-pc-byte-and-inc) retval))
t)
(defun ez-op-mod (a b)
(error "Not implemented"))
-(defun ez-op-callf (operands operand-types)
+(defun ez-op-callfv (operands operand-types)
(let* ((raddr (car operands))
(call-operands (cdr operands))
(r (* 2 raddr))
(L (ez-mem-ref-byte r))
(n (length call-operands))
(new-pc (+ r 1 (* L 2))))
- (ez-add-call-stack-frame new-pc)
- (dotimes (i L)
- (if (< i n)
- (ez-set-local-var (+ i 1) (elt call-operands i))
- (ez-set-local-var (+ i 1) (ez-mem-ref-word (+ r 1 (* 2 i)))))))
+ (if (= raddr 0)
+ (ez-set-var (ez-read-pc-byte-and-inc) 0) ; Simply return 0
+ (ez-add-call-stack-frame new-pc)
+ (dotimes (i L)
+ (if (< i n)
+ (ez-set-local-var (+ i 1) (elt call-operands i))
+ (ez-set-local-var (+ i 1) (ez-mem-ref-word (+ r 1 (* 2 i))))))))
t)
(defun ez-op-test-attr (operands operand-types)