From 2cbb10fc6b1daacfc331880ef39245307e976b1d Mon Sep 17 00:00:00 2001 From: mRnea Date: Sat, 3 Aug 2024 19:34:43 +0300 Subject: Added string literals --- assembly.lisp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'assembly.lisp') diff --git a/assembly.lisp b/assembly.lisp index e872ee8..c1efe45 100644 --- a/assembly.lisp +++ b/assembly.lisp @@ -127,9 +127,14 @@ ;;; Hopefully these two are done, need testing... ;; ( -- a) -(defop (push a) (:lex nil) +(defop (push-int a) (:lex nil) ("push ~d" a)) +(defop (push-str len addr str) (:lex nil) + (progn (:write ("push ~d" len) + ("push str_~d" addr)) + (list :string addr str))) + (defop + () (rbx rax -- (:add rax rbx))) @@ -236,14 +241,28 @@ (:write ("pop ~a" (aref call-regs i))) (finally (:write "syscall")))) +(defun comment-safe-str (str) + "Handle newlines for asm comment" + (with-output-to-string (new-str) + (iter (for ch in-string str with-index i) + (cond ((> i 10) + (princ "..." new-str) + (finish)) + ((char= #\Newline ch) + (princ "\\n" new-str)) + (t (write-char ch new-str)))))) + (defun gen-header (op str) - (format str " ;; -- ~s --~%" op)) + (format str " ;; -- ~s --~%" + (mapcar (lambda (x) (if (stringp x) (comment-safe-str x) x)) + op))) (defun gen-code (op str) (let ((op-fn (gethash (string (car op)) *operations*))) - (if (null op-fn) - (error "~s is not a valid op" op) - (apply op-fn str (cdr op))))) + (when (null op-fn) + (error "~s is not a valid op" op)) + (gen-header op str) + (apply op-fn str (cdr op)))) (defun gen-dump (str) (format str "~{~a~%~}" -- cgit v1.2.3