summaryrefslogtreecommitdiff
path: root/cl-forth.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'cl-forth.lisp')
-rw-r--r--cl-forth.lisp30
1 files changed, 17 insertions, 13 deletions
diff --git a/cl-forth.lisp b/cl-forth.lisp
index 9d66532..e4b166c 100644
--- a/cl-forth.lisp
+++ b/cl-forth.lisp
@@ -197,25 +197,29 @@
;;; COMPILER
+(defun write-program (program out &key mem-cap)
+ (format out "~a~%" "segment .text")
+ (gen-dump out)
+ (format out "~{~a~%~}" '("global _start"
+ "_start:"))
+ (iter (for op in-sequence program)
+ (gen-header op out)
+ (gen-code op out))
+ (gen-header '(exit 0) out)
+ (gen-code '(exit 0) out)
+ (format out "~a~%" "segment .bss")
+ (format out "~a ~a~%" "bel: resb" mem-cap))
+
(defun generate-program (program &key (path "output.asm") (compile nil)
(mem-cap 640000))
(with-open-file (out path :direction :output
:if-exists :supersede)
- (format out "~a~%" "segment .text")
- (gen-dump out)
- (format out "~{~a~%~}" '("global _start"
- "_start:"))
- (iter (for op in-sequence program)
- (gen-header op out)
- (gen-code op out))
- (gen-header '(exit 0) out)
- (gen-code '(exit 0) out)
- (format out "~a~%" "segment .bss")
- (format out "~a ~a~%" "bel: resb" mem-cap))
+ (write-program program out :mem-cap mem-cap))
(when compile
- (run `("nasm" "-felf64" ,path))
+ (run `("nasm" "-felf64" ,path) :output t)
(let ((name (first (uiop:split-string path :separator '(#\.)))))
- (run `("ld" "-o" ,name ,(concatenate 'string name ".o"))))))
+ (run `("ld" "-o" ,name ,(concatenate 'string name ".o"))
+ :output t))))
(defun compile-program (path)
(generate-program (make-program path) :compile t))