diff --git a/wip-duuqnd/user-side-compiler/backend/code-generator.lisp b/wip-duuqnd/user-side-compiler/backend/code-generator.lisp index 50d1938..df78525 100644 --- a/wip-duuqnd/user-side-compiler/backend/code-generator.lisp +++ b/wip-duuqnd/user-side-compiler/backend/code-generator.lisp @@ -102,6 +102,22 @@ (emit-sta :address (data-reference data)) (setf *last-instruction* (list :store data))))) +(defun emit-store-bool (data) + "Stores the inverse of the zeroflag to DATA. Inverse so that non-0 is TRUE." + ;; The "DATA is stored"-case + (if (or (null (allocation-details data)) + (member (strategy (allocation-details data)) + '(:constant :accumulator))) + (setf *last-instruction* '(:useless)) + (progn + (emit-asm-instruction :opcode :php :byte-length 1) + (emit-asm-instruction :opcode :pla :byte-length 1) + (emit-asm-instruction :opcode :and :operand #b00000010 :byte-length 2) + (emit-asm-instruction :opcode :lsr-a :byte-length 1) + (emit-asm-instruction :opcode :not :operand #b00000001 :byte-length 2) + (emit-sta :address (data-reference data)) + (setf *last-instruction* '(:store-zero-flag data))))) + (defun emit-load-data (data) (if (or (member (strategy (allocation-details data)) '(:accumulator :direct-to-argvec)) @@ -114,6 +130,24 @@ (emit-lda :address (data-reference data))) (setf *last-instruction* (list :load data))))) +(defun emit-load-bool (data) + (if (or (member (strategy (allocation-details data)) + '(:accumulator)) + (equal *last-instruction* (list :store-zero-flag data)) + (equal *last-instruction* (list :load-zero-flag data))) + (setf *last-instruction* '(:useless)) + (progn + (if (eql (strategy (allocation-details data)) :constant) + (progn + (emit-lda :immediate (ir-constant-value data)) + (emit-asm-instruction :opcode :and :operand 1 :byte-length 1) + (emit-cmp :immediate 1)) + (progn + (emit-lda :address (data-reference data)) + (emit-asm-instruction :opcode :and :operand 1 :byte-length 1) + (emit-cmp :immediate 1))) + (setf *last-instruction* (list :load-zero-flag data))))) + (defmethod compile-ir ((inst ir-inst)) (warn "Skipped compiling ~A; no COMPILE-IR method" inst))