Added string literals

This commit is contained in:
2024-08-03 19:34:43 +03:00
parent 724519dad1
commit 2cbb10fc6b
3 changed files with 59 additions and 14 deletions

View File

@@ -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~%~}"