From 49b58b2d57eb9ae5a5d587bf6144f198797da0a2 Mon Sep 17 00:00:00 2001 From: mRnea Date: Mon, 29 Jul 2024 00:36:06 +0300 Subject: minor change to run to make it more generic --- cl-forth.lisp | 30 +++++++++++++++++------------- main.lisp | 2 +- util.lisp | 4 ++-- 3 files changed, 20 insertions(+), 16 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)) diff --git a/main.lisp b/main.lisp index 578fa01..8a90c32 100644 --- a/main.lisp +++ b/main.lisp @@ -39,7 +39,7 @@ (defun example-run () (example-compile) - (run '("test/output"))) + (run '("test/output") :output t)) (defun start-forth-repl () (iter (for line = (progn (format t "~&> ") (read-line))) diff --git a/util.lisp b/util.lisp index b97b0fa..e4a9ccb 100644 --- a/util.lisp +++ b/util.lisp @@ -20,9 +20,9 @@ (defun mklist (form) (if (listp form) form (list form))) -(defun run (args) +(defun run (args &rest options) (format t "~{~a~^ ~}~%" args) - (uiop:run-program args :output *standard-output*)) + (apply #'uiop:run-program args options)) (defun from-root (path) (merge-pathnames path (asdf:system-source-directory :cl-forth))) -- cgit v1.2.3