summaryrefslogtreecommitdiff
path: root/src/emit.lisp
diff options
context:
space:
mode:
authorSiddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com>2025-04-12 13:06:51 -0400
committerGitHub <noreply@github.com>2025-04-12 13:06:51 -0400
commitfc20e7e7276b712f1e8db773b9215f900e877169 (patch)
treecaecdd1499d2e391cd5bd2dcde3aebfade002a09 /src/emit.lisp
parent5dbf0b63988b42c112ca0087cbbbb090566df5c1 (diff)
parent639098b1ea82be82bd18a4af415458fcbaf5e20b (diff)
Merge pull request #8 from bdunahu/bdunahu
Add write raw bytes stage
Diffstat (limited to 'src/emit.lisp')
-rw-r--r--src/emit.lisp17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/emit.lisp b/src/emit.lisp
index acc2772..213eb1a 100644
--- a/src/emit.lisp
+++ b/src/emit.lisp
@@ -2,7 +2,7 @@
(defun fits-in-X-bits (n)
"Returns the number of bits required to represent N"
- (ceiling (/ (log (ceiling n (log 2))) (log 2))))
+ (ceiling (/ (log n) (log 2))))
(defmacro generate-type-map (ops)
"Generates an alist where the key corresponds to an element in
@@ -11,8 +11,7 @@ number of bits required to represent all
concatenated with TYPE."
`(let ((i 0)
(opsize (fits-in-X-bits (length ,ops))))
- (mapcar (lambda (x)
- (incf i)
+ (mapcar (lambda (x) (incf i)
(cons x (util:format-as-binary i opsize)))
,ops)))
@@ -32,7 +31,9 @@ concatenated with TYPE."
(mapcar (lambda (x) (util:format-as-binary x 32)) lst))
(defun x (&rest lst)
- lst)
+ (append lst
+ ;; add a halt to the end of the instructions list
+ (list (r "QUOT" (rr 0) (rr 0) (rr 0)))))
(defun r (mnemonic s1 s2 d)
(concatenate
@@ -51,16 +52,16 @@ concatenated with TYPE."
(util:format-as-binary val 5)
(error (format nil "~a is not a valid register id!~%" val))))
-(defun imm (val) val)
-
(defun l (l s)
(let ((d (util:get-label l)))
(- d s)))
(defun var (s)
(let ((pos (util:get-variable s)))
- (+ pos parse:line-number)))
+ (+ pos parse:line-number 1)))
(defun emit (p)
- (format t "~a~%" p)
(eval p))
+
+(defun ast->str (p)
+ (format nil "~a" p))