(defun ez-get-obj-prop (obj prop)
(let* ((prop-addr (ez-get-obj-prop-addr obj prop))
(size-byte (ez-mem-ref-byte prop-addr)))
- (if (= prop-addr 0)
+ (if (= size-byte 0)
(ez-get-prop-default prop)
(let ((prop-len (ez-get-prop-len size-byte))
(data-addr (+ prop-addr 1)))
(setq optype '0op
opcode (- opbyte #xb0)))
((<= #xC0 opbyte #xDF)
- (error "Unsupported op" opbyte))
+ (error "Unsupported op %x" opbyte))
((<= #xE0 opbyte #xFF)
(setq optype 'var
opcode (- opbyte #xe0))
operand-types (cdr operands-and-types)))))
(let ((table-row (assoc (list optype opcode) ez-op-table)))
(unless table-row
- (error "Unsupported op" instr-pc optype opcode operands operand-types))
+ (error "Unsupported op PC:%x Optype:%s Opcode:%x Operands:%s Operand-types:%s"
+ instr-pc optype opcode operands operand-types))
(let ((mnemonic (elt table-row 1)))
(message "PC:%x Optype:%s Opcode:%x Mnemonic:%s Operands:%s"
instr-pc optype opcode mnemonic operands))
(defun ez-do-branch (branch)
(let* ((branch-byte (ez-read-pc-byte-and-inc))
(invert (= 0 (logand branch-byte #b10000000)))
- (single-byte (= 1 (logand branch-byte #b01000000)))
+ (single-byte (> (logand branch-byte #b01000000) 0))
(offset
(if single-byte
(logand branch-byte #b00111111)
(if pos
val
(- val 8192))))))
- (cond
- ((= offset 0)
- (ez-op-rfalse))
- ((= offset 1)
- (ez-op-rtrue))
- (t
- (ez-set-pc (+ (ez-get-pc) offset -2))))))
+ (if (or (and branch (not invert))
+ (and (not branch) invert))
+ (cond
+ ((= offset 0)
+ (ez-op-rfalse))
+ ((= offset 1)
+ (ez-op-rtrue))
+ (t
+ (ez-set-pc (+ (ez-get-pc) offset -2)))))))
;; Operations
((1op #x01) get_sibling ez-op-get-sibling)
((1op #x02) get_child ez-op-get-child)
((1op #x03) get_parent ez-op-get-parent)
+ ((2op #x0A) test_attr ez-op-test-attr)
((var #x03) put_prop ez-op-put-prop)))
(defun ez-op-ret (operands &optional operand-types)
t)
(defun ez-op-rtrue (&optional operands operand-types)
- (ez-op-ret (list 1)))
+ (ez-op-ret (list 1))
+ t)
(defun ez-op-rfalse (&optional operands operand-types)
- (ez-op-ret (list 0)))
+ (ez-op-ret (list 0))
+ t)
(defun ez-op-jz (operands operand-types)
(ez-do-branch (= (car operands) 0))
(ez-set-local-var (+ i 1) (ez-mem-ref-word (+ r 1 (* 2 i)))))))
t)
+(defun ez-op-test-attr (operands operand-types)
+ (let ((obj (car operands))
+ (attr (cadr operands)))
+ (ez-do-branch (= 1 (ez-get-obj-attr obj attr)))
+ t))
+
(defun ez-op-get-sibling (operands operand-types)
(let ((sib (ez-get-obj-sibling (car operands))))
(ez-set-var (ez-read-pc-byte-and-inc) sib)
- (ez-do-branch (> sib 0))))
+ (ez-do-branch (> sib 0))
+ t))
(defun ez-op-get-child (operands operand-types)
(let ((child (ez-get-obj-child (car operands))))
(ez-set-var (ez-read-pc-byte-and-inc) child)
- (ez-do-branch (> child 0))))
+ (ez-do-branch (> child 0))
+ t))
(defun ez-op-get-parent (operands operand-types)
(let ((parent (ez-get-obj-parent (car operands))))
(ez-set-var (ez-read-pc-byte-and-inc) parent)
- (ez-do-branch (> parent 0))))
+ (ez-do-branch (> parent 0))
+ t))
(defun ez-op-put-prop (operands operand-types)
(let* ((obj (car operands))
(prop (cadr operands))
(a (caddr operands)))
- (ez-set-obj-prop obj prop a)))
+ (ez-set-obj-prop obj prop a)
+ t))
;; Main