diff options
author | mRnea <akannemre@gmail.com> | 2024-08-03 19:34:43 +0300 |
---|---|---|
committer | mRnea <akannemre@gmail.com> | 2024-08-03 19:34:43 +0300 |
commit | 2cbb10fc6b1daacfc331880ef39245307e976b1d (patch) | |
tree | 593c37fa03c17ce6ac49653fd4c198355804b575 /assembly.lisp | |
parent | 724519dad14aeb62571866923c46bf47d5963d02 (diff) |
Added string literals
Diffstat (limited to 'assembly.lisp')
-rw-r--r-- | assembly.lisp | 29 |
1 files changed, 24 insertions, 5 deletions
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~%~}" |