X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=ez.git;a=blobdiff_plain;f=ez.el;h=95547d1839b0ad1b7a9e955b30c5656818cc304d;hp=1fb0f655e9fcfc0bc9fc99d1c1bc85f25600c4e6;hb=a437668aefaafa527eb913ae3f990381436347ab;hpb=8ed7e627cfe9175458a7bae4cbf8bbb35cfc00b4 diff --git a/ez.el b/ez.el index 1fb0f65..95547d1 100644 --- a/ez.el +++ b/ez.el @@ -55,6 +55,14 @@ 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 @@ -106,10 +114,14 @@ (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 @@ -322,20 +334,25 @@ (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 () @@ -444,10 +461,11 @@ (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 () @@ -456,15 +474,15 @@ (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)))))))))))))) @@ -536,7 +554,7 @@ ((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) @@ -555,6 +573,7 @@ (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) @@ -696,18 +715,20 @@ (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)